home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / exec2.arc / EXEC.ASM next >
Encoding:
Assembly Source File  |  1985-11-28  |  4.6 KB  |  219 lines

  1. code    segment
  2.     assume cs:code,ds:code
  3.     org    100h
  4.  
  5.  
  6. ;exec written by alan vanchura
  7. ;
  8. ;friendlysoft inc
  9. ;3638 west pioneer pkwy
  10. ;arlington tx 76013
  11.  
  12. ;817 496 8151    (home)
  13.  
  14. ;this program will save current drive and directory
  15. ;then will switch to drive and pathname
  16. ;then exec the filename.ext (under 3.0 a pathname may be added to filename.ext
  17. ;when finished it will return to orginal drive and pathname
  18. ;
  19. ;command.com must be accessable by exec through set comspec=c:\command.com
  20. ;Also if filename.ext is not in the current directory, then drive:pathname\
  21. ;must be added
  22. ;
  23. ;SYNTAX:
  24. ;        exec d:\pathname filename.ext  [optional parms]
  25. ;
  26. ;EXAMPLES:
  27. ;        exec c:\qmodem qmodem.com
  28. ;
  29. ;        exec c:\dos format.com a:/s/1
  30. ;
  31. ;        exec c:\games\sub1 c:\dos\basica.com menu.bas
  32. ;
  33.  
  34. start    proc
  35.     jmp    begin
  36.  
  37.     db    13,"written by Alan Vanchura, FriendlySoft,Inc.",13,10
  38.     db    "version 2.0     04/14/85",13,10
  39.     db    "version 2.1     05/16/85",13,10,1ah
  40.  
  41. drive$        db    0        ;current drive
  42. path$        db    66 dup(0)   ;current pathname
  43. pathc$        db    80 dup(0)   ;drive and path to switch to
  44. namec$        db    40 dup(0)   ;pathname\filename to exec
  45. command$    db    40 dup(0)   ;optional parms following filename
  46.  
  47. error1$ db    "Memory shrink error$"
  48.  
  49. error3$ db    "Exec failure.$"
  50. error4$ db    "written by Alan Vanchura, FriendlySoft,Inc.",13,10
  51.     db    "version 2.0     04/14/85",13,10
  52.     db    "version 2.1     05/16/85",13,10
  53.     db    "Command line syntax is ",13,10
  54.     db    "exec d:\pathname d:\path\filename.ext [optional parms]$"
  55.  
  56. error5$ db    "drive must be specified before pathname$"
  57. error6$ db    "invalid drive specified$"
  58. error7$ db    "invalid path specified$"
  59.  
  60. sp_save     dw    0
  61.  
  62. parm_block    label    word
  63. environment_seg dw    0
  64. command_line    dd    0
  65. default_fcb1    dd    0
  66. default_fcb2    dd    0
  67.  
  68. begin:
  69.     mov    ah,19h
  70.     int    21h
  71.     mov    dl,al
  72.     mov    drive$,dl            ;drive
  73.  
  74.     mov    ah,47h                ;get directory
  75.     lea    si,path$
  76.     inc    dl                ;current drive
  77.     int    21h
  78.  
  79.     lea    bx,new_dta            ;set size of needed code
  80.     shr    bx,1
  81.     shr    bx,1
  82.     shr    bx,1
  83.     shr    bx,1
  84.     inc    bx
  85.     mov    ah,4ah
  86.     int    21h                ;shrink memory
  87.     jnc    rt110
  88.     lea    dx,error1$
  89.     jmp    exit
  90. rt110:
  91.     cld
  92.     mov    si,offset 80h
  93.     lodsb
  94.     and    al,al                ;any thing on command line?
  95.     jnz    rt120                ;yes
  96.     lea    dx,error4$            ;else show command syntax
  97.     jmp    exit
  98. rt120:
  99.     lodsb                    ;space
  100.     lodsb                    ;get drive letter
  101.     and    al,0ffh-20h            ;force to uppercase
  102.     sub    al,"A"                          ;adjust for set drive call
  103.     mov    ah,0eh
  104.     mov    dl,al
  105.     int    21h                ;set drive
  106.     cmp    al,dl                ;drive set?
  107.     ja    rt140                ;yes
  108.     lea    dx,error6$            ;drive letter invalid
  109.     jmp    exit
  110. rt140:
  111.     lodsb                    ;make sure
  112.     cmp    al,":"                          ;valid drive and colon
  113.     je    rt150
  114.     lea    dx,error5$            ;drive must be specified
  115.     jmp    exit
  116. rt150:
  117.     lea    di,pathc$            ;
  118. rt151:
  119.     lodsb                    ;move pathname to save area
  120.     cmp    al," "
  121.     je    rt160
  122.     stosb
  123.     jmp    rt151
  124. rt160:
  125.     xor    al,al                ;end it with zero
  126.     stosb
  127.     lea    di,namec$
  128. rt161:
  129.     lodsb                    ;move filename to save area
  130.     cmp    al," "
  131.     je    rt170
  132.     cmp    al,0dh
  133.     je    rt170
  134.     stosb
  135.     jmp    rt161
  136. rt170:
  137.     mov    word ptr command_line,si    ;save for check for parameters
  138.     xor    al,al
  139.     stosb
  140.  
  141.     lea    dx,pathc$            ;set path
  142.     mov    ah,3bh
  143.     int    21h
  144.     jnc    rt180                ;no error
  145.     lea    dx,error7$            ;invalid path
  146.     jmp    exit
  147. rt180:
  148.     mov    sp_save,sp            ;save stack pointer
  149.  
  150.     lea    di,command$+1            ;command line save area
  151.     mov    si,word ptr command_line
  152.     cmp    byte ptr [si-1],0dh        ;any parms?
  153.     je    rt189                ;no
  154.     mov    cx,39                ;length of parm save area
  155. rt181:
  156.     lodsb                    ;move parms to save area
  157.     stosb
  158.     cmp    al,0dh                ;of command line
  159.     je    rt189
  160.     inc    byte ptr command$        ;adjust counter at start
  161.     loop    rt181
  162. rt189:
  163.     mov    ax,word ptr ds:[002ch]        ;setup paramater block
  164.     mov    environment_seg,ax        ;for exec function
  165.     mov    word ptr command_line,offset command$
  166.     mov    word ptr command_line+2,ds
  167.     mov    word ptr default_fcb1,5ch
  168.     mov    word ptr default_fcb1+2,ds
  169.     mov    word ptr default_fcb2,6ch
  170.     mov    word ptr default_fcb2+2,ds
  171.  
  172.     lea    si,command$+1            ;parse any parms
  173.     mov    di,word ptr default_fcb1    ;to fcb at 5ch
  174.     mov    ah,29h                ;for pass to program being
  175.     mov    al,0                ;invoked
  176.     int    21h
  177.  
  178.     lea    dx,namec$            ;exec filename.ext
  179.     lea    bx,parm_block
  180.     mov    ah,4bh
  181.     mov    al,00h
  182.     int    21h
  183.  
  184.     cli
  185.     mov    ax,cs                ;restore seg registers
  186.     mov    ds,ax
  187.     mov    es,ax
  188.     mov    ss,ax
  189.     mov    sp,sp_save
  190.     sti
  191.  
  192.     lea    dx,error3$            ;any errors
  193.     jc    exit                ;yes. exec not successful
  194.  
  195.     mov    dl,drive$            ;restore to orginal drive
  196.     mov    ah,0eh
  197.     int    21h
  198.  
  199.     lea    dx,path$            ;restore to orginal path
  200.     cmp    byte ptr path$,'\'
  201.     je    rt190
  202.     dec    dx
  203.     mov    byte ptr path$-1,'\'
  204. rt190:
  205.     mov    ah,3bh
  206.     int    21h
  207.     int    20h                ;finished
  208. exit:
  209.     mov    ah,9
  210.     int    21h
  211.     int    20h
  212.  
  213. start    endp
  214.  
  215. new_dta     dw    0
  216.  
  217. code    ends
  218.     end start
  219.